package kr.saeildamil.androidstudty.ch13;

import kr.saeildamil.androidstudty.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;

public class DateTimePicker extends Activity {
	DatePicker mDate;
	TextView mTextDate;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_datetimepicker);
		
		mDate=(DatePicker) findViewById(R.id.ch13_datetimepicker_datepicker);
		mTextDate=(TextView) findViewById(R.id.ch13_datetimepicker_datetv);
		mDate.init(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(), new DatePicker.OnDateChangedListener() {
			
			@Override
			public void onDateChanged(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				mTextDate.setText(String.format("%d/%d/%d", year, monthOfYear+1,dayOfMonth));
			}
		});
		
		findViewById(R.id.ch13_datetimepicker_datebtn).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String result=String.format("%d년 %월 %d일", mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth()+1,mDate.getDayOfMonth());
				Toast.makeText(DateTimePicker.this, result, 0).show();
			}
		});
	}
}
